<!DOCTYPE html>





<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 3.9.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.4.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png?v=7.4.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png?v=7.4.0">
  <link rel="mask-icon" href="/images/avatar.svg?v=7.4.0" color="#222">
  <link rel="alternate" href="/atom.xml" title="Anemone's Blog" type="application/atom+xml">
  <meta name="google-site-verification" content="Re5JdegRYzNFco-rC9lYIsvSWIgh5JvyfhuEaZCeFCk">
  <meta name="baidu-site-verification" content="opTC8YN3Pn">

<link rel="stylesheet" href="/css/main.css?v=7.4.0">


<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '7.4.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: 'GB90MXPJ1C',
      apiKey: '05d808da3baf50ac2f2fad2dc3a3cd8f',
      indexName: 'dev_blog',
      hits: {"per_page":20},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":true,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    },
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="CSRF成因GET型脆弱代码存在CSRF的GET型请求如下：1234567891011121314151617181920@app.route(&apos;/get&apos;, methods=[&apos;GET&apos;])def get():    if session.get(&apos;user&apos;,&apos;&apos;)==&apos;admin&apos;:        ret = &quot;Admin do something!&quot;    else:        ret">
<meta name="keywords" content="Web安全,CSRF,防御">
<meta property="og:type" content="article">
<meta property="og:title" content="CSRF成因、攻击和防御">
<meta property="og:url" content="http://anemone.top/csrf-CSRF成因、攻击和防御/index.html">
<meta property="og:site_name" content="Anemone&#39;s Blog">
<meta property="og:description" content="CSRF成因GET型脆弱代码存在CSRF的GET型请求如下：1234567891011121314151617181920@app.route(&apos;/get&apos;, methods=[&apos;GET&apos;])def get():    if session.get(&apos;user&apos;,&apos;&apos;)==&apos;admin&apos;:        ret = &quot;Admin do something!&quot;    else:        ret">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://anemone.top/csrf-CSRF成因、攻击和防御/1549283807815.png">
<meta property="og:image" content="http://anemone.top/csrf-CSRF成因、攻击和防御/1549284215038.png">
<meta property="og:image" content="http://anemone.top/csrf-CSRF成因、攻击和防御/1549284680614.png">
<meta property="og:image" content="http://anemone.top/csrf-CSRF成因、攻击和防御/1549285932946.png">
<meta property="og:updated_time" content="2019-09-22T10:14:18.603Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="CSRF成因、攻击和防御">
<meta name="twitter:description" content="CSRF成因GET型脆弱代码存在CSRF的GET型请求如下：1234567891011121314151617181920@app.route(&apos;/get&apos;, methods=[&apos;GET&apos;])def get():    if session.get(&apos;user&apos;,&apos;&apos;)==&apos;admin&apos;:        ret = &quot;Admin do something!&quot;    else:        ret">
<meta name="twitter:image" content="http://anemone.top/csrf-CSRF成因、攻击和防御/1549283807815.png">
  <link rel="canonical" href="http://anemone.top/csrf-CSRF成因、攻击和防御/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>CSRF成因、攻击和防御 | Anemone's Blog</title>
  








  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">
  <div class="container use-motion">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Anemone's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-about">
      
    

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-tags">
      
    

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-categories">
      
    

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger">
        
          <i class="fa fa-search fa-fw"></i>搜索</a>
      </li>
    
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input" id="search-input"></div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="algolia-results">
  <div id="algolia-stats"></div>
  <div id="algolia-hits"></div>
  <div id="algolia-pagination" class="algolia-pagination"></div>
</div>

  
</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
            

          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
      <article itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block post">
    <link itemprop="mainEntityOfPage" href="http://anemone.top/csrf-CSRF成因、攻击和防御/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Anemone">
      <meta itemprop="description" content="关注Web安全、移动安全、Fuzz测试和机器学习">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Anemone's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">CSRF成因、攻击和防御

          
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-02-04 20:24:21" itemprop="dateCreated datePublished" datetime="2019-02-04T20:24:21+08:00">2019-02-04</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-09-22 18:14:18" itemprop="dateModified" datetime="2019-09-22T18:14:18+08:00">2019-09-22</time>
              </span>
            
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/Web安全-CSRF/" itemprop="url" rel="index"><span itemprop="name">Web安全-CSRF</span></a></span>

                
                
              
            </span>
          

          
            <span id="/csrf-CSRF成因、攻击和防御/" class="post-meta-item leancloud_visitors" data-flag-title="CSRF成因、攻击和防御" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="CSRF成因"><a href="#CSRF成因" class="headerlink" title="CSRF成因"></a>CSRF成因</h1><h2 id="GET型"><a href="#GET型" class="headerlink" title="GET型"></a>GET型</h2><h3 id="脆弱代码"><a href="#脆弱代码" class="headerlink" title="脆弱代码"></a>脆弱代码</h3><p>存在CSRF的GET型请求如下：</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@app.route('/get', methods=['GET'])</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">if</span> session.get(<span class="string">'user'</span>,<span class="string">''</span>)==<span class="string">'admin'</span>:</span><br><span class="line">        ret = <span class="string">"Admin do something!"</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        ret = <span class="string">"No Privilege..."</span></span><br><span class="line">    <span class="keyword">return</span> ret</span><br><span class="line"></span><br><span class="line"><span class="meta">@app.route('/login', methods=['GET'])</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">login</span><span class="params">()</span>:</span></span><br><span class="line">    user=request.args.get(<span class="string">"user"</span>, <span class="string">"Null"</span>)</span><br><span class="line">    session[<span class="string">"user"</span>]=user</span><br><span class="line">    template=<span class="string">"""</span></span><br><span class="line"><span class="string">    &lt;h3&gt; Login as &#123;&#123; user &#125;&#125;... &lt;/h3&gt;</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    <span class="keyword">return</span> render_template_string(template, user=user)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    app.run(host=<span class="string">'127.0.0.1'</span>, port=<span class="number">8888</span>, debug=<span class="literal">True</span>)</span><br></pre></td></tr></table></figure><a id="more"></a>

<p>先使用<a href="http://127.0.0.1:8888/login?user=admin模拟用户admin登陆，从代码可以看到登陆后网站将用户身份（简单起见就是用户名）保存到session中。" target="_blank" rel="noopener">http://127.0.0.1:8888/login?user=admin模拟用户admin登陆，从代码可以看到登陆后网站将用户身份（简单起见就是用户名）保存到session中。</a><br><img src="/csrf-CSRF成因、攻击和防御/1549283807815.png" alt="1549283807815"></p>
<p>接着访问<a href="http://127.0.0.1:8888/get可以看到用户具有这一权限，可以进行操作（假设这一链接是一个关键操作，如重置密码或泄露其他敏感信息的操作）。" target="_blank" rel="noopener">http://127.0.0.1:8888/get可以看到用户具有这一权限，可以进行操作（假设这一链接是一个关键操作，如重置密码或泄露其他敏感信息的操作）。</a></p>
<p><img src="/csrf-CSRF成因、攻击和防御/1549284215038.png" alt="1549284215038"></p>
<h3 id="攻击方法"><a href="#攻击方法" class="headerlink" title="攻击方法"></a>攻击方法</h3><p>如果用户访问了恶意网页，恶意网页诱导用户访问<a href="http://127.0.0.1:8888/get或是用js发送一个get请求，那么用户由于sessionID还存在于浏览器中，因此会在无意间使用自己的身份重置密码，如用于访问了如下内容的网页：" target="_blank" rel="noopener">http://127.0.0.1:8888/get或是用js发送一个get请求，那么用户由于sessionID还存在于浏览器中，因此会在无意间使用自己的身份重置密码，如用于访问了如下内容的网页：</a></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">title</span>&gt;</span>AJAX<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> xhr = <span class="keyword">new</span> XMLHttpRequest();</span></span><br><span class="line"><span class="javascript">    xhr.open(<span class="string">"GET"</span>, <span class="string">"http://127.0.0.1:8888/get"</span>, <span class="literal">true</span>);</span></span><br><span class="line"><span class="javascript">    xhr.withCredentials = <span class="literal">true</span>;</span></span><br><span class="line">    xhr.send();</span><br><span class="line"><span class="javascript">    xhr.onreadystatechange = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span></span><br><span class="line">        if(xhr.readyState === 4 &amp;&amp; xhr.status === 200)&#123;</span><br><span class="line">            alert(xhr.responseText);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>尽管同源策略导致js拿不到结果，但是请求仍然会正常发送：</p>
<p><img src="/csrf-CSRF成因、攻击和防御/1549284680614.png" alt="1549284680614"></p>
<h2 id="POST-表单型"><a href="#POST-表单型" class="headerlink" title="POST 表单型"></a>POST 表单型</h2><h3 id="脆弱代码-1"><a href="#脆弱代码-1" class="headerlink" title="脆弱代码"></a>脆弱代码</h3><p>有人认为CSRF产生的原因是因为GET请求类型造成的，其实不然，如下就是一个POST类型的代码，它同样存在CSRF问题：<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@app.route('/post', methods=['GET','POST'])</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">post</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">if</span> request.method == <span class="string">'GET'</span>:</span><br><span class="line">        template=<span class="string">"""</span></span><br><span class="line"><span class="string">        &lt;form action="http://127.0.0.1:8888/reset" method="POST"&gt;</span></span><br><span class="line"><span class="string">        &lt;input name="action" type="text"&gt;</span></span><br><span class="line"><span class="string">        &lt;input type="submit"&gt;</span></span><br><span class="line"><span class="string">        &lt;/form&gt;</span></span><br><span class="line"><span class="string">        """</span></span><br><span class="line">        <span class="keyword">return</span> render_template_string(template)</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        print(request.form)</span><br><span class="line">        data=request.form[<span class="string">"action"</span>]</span><br><span class="line">        print(<span class="string">"session:"</span>,session)</span><br><span class="line">        <span class="keyword">if</span> session.get(<span class="string">'user'</span>,<span class="string">''</span>)==<span class="string">'admin'</span>:</span><br><span class="line">            print(<span class="string">"Admin do"</span>, data)</span><br><span class="line">            <span class="keyword">return</span> <span class="string">"Admin do "</span>+data</span><br><span class="line"></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            print(<span class="string">"No Privilege2..."</span>)</span><br><span class="line">            <span class="keyword">return</span> <span class="string">"No Privilege2..."</span></span><br></pre></td></tr></table></figure></p>
<h3 id="攻击方法-1"><a href="#攻击方法-1" class="headerlink" title="攻击方法"></a>攻击方法</h3><p>攻击者只需要同样的伪造POST表单即可，这里我们换用<code>fetch()</code>试一下，当然<code>XMLHttpRequest()</code>也可以。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fetch(<span class="string">'http://127.0.0.1:8888/post'</span>,&#123;<span class="attr">method</span>: <span class="string">'POST'</span>, <span class="attr">credentials</span>: <span class="string">'include'</span>, <span class="attr">headers</span>:&#123;<span class="string">'Content-Type'</span>: <span class="string">'application/x-www-form-urlencoded'</span>&#125;, <span class="attr">body</span>:<span class="string">'action=reset+password'</span>&#125;)</span><br></pre></td></tr></table></figure>
<p>尽管同源再一次没让我们拿到结果，但是请求还是发过去了：</p>
<p><img src="/csrf-CSRF成因、攻击和防御/1549285932946.png" alt="1549285932946"></p>
<h2 id="POST-JSON型"><a href="#POST-JSON型" class="headerlink" title="POST JSON型"></a>POST JSON型</h2><p>如果服务器严格限制了<code>Content-Type=application/json</code>，理论上是不存在CSRF的，因为该请求属于非简单请求，非简单请求会发先检请求确认是否允许跨域，如果不允许跨域的话js就没法使用cookie。</p>
<p>但是若服务器不判断content-type，那么攻击者就可以使用表单或是js伪造一个<code>Content-Type=text/plain</code>的请求。</p>
<h3 id="脆弱代码-2"><a href="#脆弱代码-2" class="headerlink" title="脆弱代码"></a>脆弱代码</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@app.route('/json', methods=['GET','POST','OPTIONS'])</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">_json</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">if</span> request.method == <span class="string">'GET'</span>:</span><br><span class="line">        template=<span class="string">"""</span></span><br><span class="line"><span class="string">        &lt;script type="text/javascript"&gt;</span></span><br><span class="line"><span class="string">        function submitRequest() &#123;</span></span><br><span class="line"><span class="string">            var xhr = new XMLHttpRequest();</span></span><br><span class="line"><span class="string">            xhr.open("POST", "http://127.0.0.1:8888/json", true);</span></span><br><span class="line"><span class="string">            xhr.setRequestHeader("Accept", "*/*");</span></span><br><span class="line"><span class="string">            xhr.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");</span></span><br><span class="line"><span class="string">            xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");</span></span><br><span class="line"><span class="string">            xhr.withCredentials = true;</span></span><br><span class="line"><span class="string">            xhr.send(JSON.stringify(&#123;"action":"change passwd..."&#125;));</span></span><br><span class="line"><span class="string">            xhr.onreadystatechange = function()&#123;</span></span><br><span class="line"><span class="string">                if(xhr.readyState === 4 &amp;&amp; xhr.status === 200)&#123;</span></span><br><span class="line"><span class="string">                    alert(xhr.responseText);</span></span><br><span class="line"><span class="string">                &#125;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">        &lt;/script&gt;</span></span><br><span class="line"><span class="string">        &lt;button onclick="submitRequest()"&gt;Conform&lt;/button&gt;</span></span><br><span class="line"><span class="string">        """</span></span><br><span class="line">        <span class="keyword">return</span> render_template_string(template)</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        <span class="keyword">if</span> session.get(<span class="string">'user'</span>,<span class="string">''</span>)==<span class="string">'admin'</span>:</span><br><span class="line">            data=json.loads(request.get_data(as_text=<span class="literal">True</span>))</span><br><span class="line">            ret=<span class="string">'Admin do '</span>+data[<span class="string">"action"</span>]</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            ret=<span class="string">"No Privilege2..."</span></span><br><span class="line">        <span class="keyword">return</span> ret</span><br></pre></td></tr></table></figure>
<h3 id="攻击方法-2"><a href="#攻击方法-2" class="headerlink" title="攻击方法"></a>攻击方法</h3><ol>
<li><p>使用表单伪造post，关键是用name字段构造一个合法的json：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">"http://127.0.0.1:8888/json"</span> <span class="attr">method</span>=<span class="string">"POST"</span> <span class="attr">enctype</span>=<span class="string">"text/plain"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">name</span>=<span class="string">'&#123;"action":"change passwd...", "test":"'</span> <span class="attr">value</span>=<span class="string">'test"&#125;'</span> <span class="attr">type</span>=<span class="string">'hidden'</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">submit</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>使用js伪造post json</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fetch(<span class="string">'http://127.0.0.1:8888/json'</span>,&#123;<span class="attr">method</span>: <span class="string">'POST'</span>, <span class="attr">credentials</span>: <span class="string">'include'</span>, <span class="attr">headers</span>:&#123;<span class="string">'Content-Type'</span>: <span class="string">'text/plain'</span>&#125;, <span class="attr">body</span>:<span class="string">'&#123;"action":"reset password"&#125;'</span>&#125;)</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h1 id="防御"><a href="#防御" class="headerlink" title="防御"></a>防御</h1><p>主要有两种手段：</p>
<ol>
<li>根据Referer判断，但是要考虑没有referer字段的情况</li>
<li>增加一个随机的Token，前端发送后，后端比较是否一致，本文主要介绍这一种方法</li>
</ol>
<h2 id="GET型-1"><a href="#GET型-1" class="headerlink" title="GET型"></a>GET型</h2><p>在产生GET请求的地方就加一个csrf_token，在处理get请求时判断csrf_token与cookie或session中的token是否一致。</p>
<h2 id="POST表单型"><a href="#POST表单型" class="headerlink" title="POST表单型"></a>POST表单型</h2><p>对于flask，使用</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> flask_wtf.csrf <span class="keyword">import</span> CSRFProtect</span><br><span class="line"></span><br><span class="line">app.config[<span class="string">'SECRET_KEY'</span>] = <span class="string">'you never guess'</span></span><br><span class="line">CSRFProtect(app)</span><br></pre></td></tr></table></figure>
<p>打开csrf保护，接着再对所有的表单添加一个隐藏字段即可：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"hidden"</span> <span class="attr">name</span>=<span class="string">"csrf_token"</span> <span class="attr">value</span>=<span class="string">"&#123;&#123; csrf_token() &#125;&#125;"</span> /&gt;</span></span><br></pre></td></tr></table></figure>
<p>增加隐藏字段后，每次POST时都会带有一个csrf_token，攻击者由于同源策略是无法获取这个token的，另外token写进session里面，即session和token是一对一关系，因此攻击者也无法通过自己的token猜测别人的token，而服务器再POST请求过来时就会验证这个token是否与session一致，若不一致则拒绝服务，这样一来攻击者就无法攻击成功了（除了把token放表单里，还可以放cookie里，攻击者仍然无法获取）</p>
<h2 id="POSTJSON型"><a href="#POSTJSON型" class="headerlink" title="POSTJSON型"></a>POSTJSON型</h2><p>理论上严格控制<code>content-type: application/json</code>就能解决问题，当然也可以用通用方法：</p>
<p>同样还是先开启CSRF防御：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> flask_wtf.csrf <span class="keyword">import</span> CSRFProtect</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">app = Flask(__name__)</span><br><span class="line">app.secret_key = <span class="string">'random_secret_key'</span></span><br><span class="line">CSRFProtect(app)</span><br></pre></td></tr></table></figure>
<p>让自己站的ajax拿到csrf_token，就像之前说的，将token放进cookie里，使用app.after_request修饰使得每个页面返回时都执行：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@app.after_request</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">after_request</span><span class="params">(response)</span>:</span></span><br><span class="line">    <span class="comment"># 调用函数生成 csrf_token</span></span><br><span class="line">    csrf_token = generate_csrf()</span><br><span class="line">    <span class="comment"># 通过 cookie 将值传给前端</span></span><br><span class="line">    response.set_cookie(<span class="string">"csrf_token"</span>, csrf_token)</span><br><span class="line">    <span class="keyword">return</span> response</span><br></pre></td></tr></table></figure>
<p>接着ajax从cookie拿到token并放到headers里，不用担心攻击者，因为由于同源策略，他们没法获取其他网站的cookie：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@app.route('/json2', methods=['GET'])</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">json2</span><span class="params">()</span>:</span></span><br><span class="line">    template = <span class="string">"""</span></span><br><span class="line"><span class="string">    &lt;html&gt;</span></span><br><span class="line"><span class="string">    &lt;title&gt;Normal&lt;/title&gt;</span></span><br><span class="line"><span class="string">    &lt;center&gt;</span></span><br><span class="line"><span class="string">    &lt;h1&gt; Reset Password &lt;/h1&gt;</span></span><br><span class="line"><span class="string">    &lt;head&gt;</span></span><br><span class="line"><span class="string">    &lt;script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"&gt;&lt;/script&gt;</span></span><br><span class="line"><span class="string">    &lt;script type="text/javascript"&gt;</span></span><br><span class="line"><span class="string">    $(document).ready(function()&#123;</span></span><br><span class="line"><span class="string">      $("button").click(function()&#123;</span></span><br><span class="line"><span class="string">        // body为"data=json"的请求</span></span><br><span class="line"><span class="string">        // var data = &#123;data: JSON.stringify(&#123;"action": "reset password"&#125;)&#125;</span></span><br><span class="line"><span class="string">        // body直接为json</span></span><br><span class="line"><span class="string">        var data = JSON.stringify(&#123;"action": "reset password"&#125;)</span></span><br><span class="line"><span class="string">        $.ajax(&#123;</span></span><br><span class="line"><span class="string">            url:"http://127.0.0.1:8888/json",</span></span><br><span class="line"><span class="string">            contentType: "application/json",</span></span><br><span class="line"><span class="string">            headers:&#123;'X-CSRFToken':$.cookie('csrf_token')&#125;,</span></span><br><span class="line"><span class="string">            dataType: "json",</span></span><br><span class="line"><span class="string">            type: 'POST',</span></span><br><span class="line"><span class="string">            data: data,</span></span><br><span class="line"><span class="string">            success: function (msg) &#123;</span></span><br><span class="line"><span class="string">                        alert(msg.status);</span></span><br><span class="line"><span class="string">                    &#125;</span></span><br><span class="line"><span class="string">            &#125;)</span></span><br><span class="line"><span class="string">      &#125;);</span></span><br><span class="line"><span class="string">    &#125;);</span></span><br><span class="line"><span class="string">    &lt;/script&gt;</span></span><br><span class="line"><span class="string">    &lt;/head&gt;</span></span><br><span class="line"><span class="string">    &lt;body&gt;</span></span><br><span class="line"><span class="string">    &lt;button&gt;Conform&lt;/button&gt;</span></span><br><span class="line"><span class="string">    &lt;/body&gt;</span></span><br><span class="line"><span class="string">    &lt;/html&gt;</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    <span class="keyword">return</span> render_template_string(template)</span><br></pre></td></tr></table></figure>
<h1 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h1><ul>
<li>CSRF-Scanner——打造全自动检测CSRF漏洞利器，<a href="https://security.tencent.com/index.php/blog/msg/24" target="_blank" rel="noopener">https://security.tencent.com/index.php/blog/msg/24</a></li>
</ul>

    </div>

    
    
    
        
      
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Anemone</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://anemone.top/csrf-CSRF成因、攻击和防御/" title="CSRF成因、攻击和防御">http://anemone.top/csrf-CSRF成因、攻击和防御/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！</li>
</ul>
</div>

      

      <footer class="post-footer">
          
            
          
          <div class="post-tags">
            
              <a href="/tags/Web安全/" rel="tag"># Web安全</a>
            
              <a href="/tags/CSRF/" rel="tag"># CSRF</a>
            
              <a href="/tags/防御/" rel="tag"># 防御</a>
            
          </div>
        

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
              
                <a href="/jsonp-JSONP原理及其安全性问题/" rel="next" title="JSONP原理及其安全性问题">
                  <i class="fa fa-chevron-left"></i> JSONP原理及其安全性问题
                </a>
              
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
              
                <a href="/ssrf-SSRF成因、攻击和防御/" rel="prev" title="SSRF成因、利用和防御">
                  SSRF成因、利用和防御 <i class="fa fa-chevron-right"></i>
                </a>
              
            </div>
          </div>
        
      </footer>
    
  </div>
  
  
  
  </article>

  </div>


          </div>
          
    
    <div class="comments" id="gitalk-container"></div>
  

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">
        
        
        
        
      

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#CSRF成因"><span class="nav-number">1.</span> <span class="nav-text">CSRF成因</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#GET型"><span class="nav-number">1.1.</span> <span class="nav-text">GET型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#脆弱代码"><span class="nav-number">1.1.1.</span> <span class="nav-text">脆弱代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#攻击方法"><span class="nav-number">1.1.2.</span> <span class="nav-text">攻击方法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#POST-表单型"><span class="nav-number">1.2.</span> <span class="nav-text">POST 表单型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#脆弱代码-1"><span class="nav-number">1.2.1.</span> <span class="nav-text">脆弱代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#攻击方法-1"><span class="nav-number">1.2.2.</span> <span class="nav-text">攻击方法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#POST-JSON型"><span class="nav-number">1.3.</span> <span class="nav-text">POST JSON型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#脆弱代码-2"><span class="nav-number">1.3.1.</span> <span class="nav-text">脆弱代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#攻击方法-2"><span class="nav-number">1.3.2.</span> <span class="nav-text">攻击方法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#防御"><span class="nav-number">2.</span> <span class="nav-text">防御</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#GET型-1"><span class="nav-number">2.1.</span> <span class="nav-text">GET型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#POST表单型"><span class="nav-number">2.2.</span> <span class="nav-text">POST表单型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#POSTJSON型"><span class="nav-number">2.3.</span> <span class="nav-text">POSTJSON型</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#参考链接"><span class="nav-number">3.</span> <span class="nav-text">参考链接</span></a></li></ol></div>
        
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
      src="/images/avatar.jpg"
      alt="Anemone">
  <p class="site-author-name" itemprop="name">Anemone</p>
  <div class="site-description" itemprop="description">关注Web安全、移动安全、Fuzz测试和机器学习</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">70</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/categories/">
          
        
        <span class="site-state-item-count">31</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        <span class="site-state-item-count">86</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>
</div>
  <div class="feed-link motion-element">
    <a href="/atom.xml" rel="alternate">
      <i class="fa fa-rss"></i>RSS
    </a>
  </div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://github.com/anemone95" title="GitHub &rarr; https://github.com/anemone95" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="mailto:anemone95@qq.com" title="E-Mail &rarr; mailto:anemone95@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
    
  </div>
  <div class="cc-license motion-element" itemprop="license">
    
  
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 – <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">anemone</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.9.0</div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.4.0</div>

        






  
  <script>
  function leancloudSelector(url) {
    return document.getElementById(url).querySelector('.leancloud-visitors-count');
  }
  if (CONFIG.page.isPost) {
    function addCount(Counter) {
      var visitors = document.querySelector('.leancloud_visitors');
      var url = visitors.getAttribute('id').trim();
      var title = visitors.getAttribute('data-flag-title').trim();

      Counter('get', `/classes/Counter?where=${JSON.stringify({ url })}`)
        .then(response => response.json())
        .then(({ results }) => {
          if (results.length > 0) {
            var counter = results[0];
            Counter('put', '/classes/Counter/' + counter.objectId, { time: { '__op': 'Increment', 'amount': 1 } })
              .then(response => response.json())
              .then(() => {
                leancloudSelector(url).innerText = counter.time + 1;
              })
            
              .catch(error => {
                console.log('Failed to save visitor count', error);
              })
          } else {
              Counter('post', '/classes/Counter', { title: title, url: url, time: 1 })
                .then(response => response.json())
                .then(() => {
                  leancloudSelector(url).innerText = 1;
                })
                .catch(error => {
                  console.log('Failed to create', error);
                });
            
          }
        })
        .catch(error => {
          console.log('LeanCloud Counter Error', error);
        });
    }
  } else {
    function showTime(Counter) {
      var visitors = document.querySelectorAll('.leancloud_visitors');
      var entries = [...visitors].map(element => {
        return element.getAttribute('id').trim();
      });

      Counter('get', `/classes/Counter?where=${JSON.stringify({ url: { '$in': entries } })}`)
        .then(response => response.json())
        .then(({ results }) => {
          if (results.length === 0) {
            document.querySelectorAll('.leancloud_visitors .leancloud-visitors-count').forEach(element => {
              element.innerText = 0;
            });
            return;
          }
          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.url;
            var time = item.time;
            leancloudSelector(url).innerText = time;
          }
          for (var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = leancloudSelector(url);
            if (element.innerText == '') {
              element.innerText = 0;
            }
          }
        })
        .catch(error => {
          console.log('LeanCloud Counter Error', error);
        });
    }
  }

  fetch('https://app-router.leancloud.cn/2/route?appId=o5UaCJdPfEG0g7MVxXSMagpT-gzGzoHsz')
    .then(response => response.json())
    .then(({ api_server }) => {
      var Counter = (method, url, data) => {
        return fetch(`https://${api_server}/1.1${url}`, {
          method: method,
          headers: {
            'X-LC-Id': 'o5UaCJdPfEG0g7MVxXSMagpT-gzGzoHsz',
            'X-LC-Key': 'c6IN1PuMV3QPltJcrHfn74Gt',
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(data)
        });
      };
      if (CONFIG.page.isPost) {
        const localhost = /http:\/\/(localhost|127.0.0.1|0.0.0.0)/;
        if (localhost.test(document.URL)) return;
        addCount(Counter);
      } else if (document.querySelectorAll('.post-title-link').length >= 1) {
        showTime(Counter);
      }
    });
  </script>






        
      </div>
    </footer>
  </div>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.1.0/lib/anime.min.js"></script>
  <script src="https://cdn.bootcss.com/velocity/1.2.1/velocity.min.js"></script>
  <script src="https://cdn.bootcss.com/velocity/1.2.1/velocity.ui.js"></script>
<script src="/js/utils.js?v=7.4.0"></script><script src="/js/motion.js?v=7.4.0"></script>
<script src="/js/schemes/pisces.js?v=7.4.0"></script>
<script src="/js/next-boot.js?v=7.4.0"></script>



  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>








  
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/instantsearch.js@2.10.4/dist/instantsearch.min.css">
<script src="//cdn.jsdelivr.net/npm/instantsearch.js@2.10.4/dist/instantsearch.min.js"></script><script src="/js/algolia-search.js?v=7.4.0"></script>











<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.bootcss.com/mermaid/8.2.6/mermaid.min.js', () => {
    mermaid.initialize({
      theme: 'forest',
      logLevel: 3,
      flowchart: { curve: 'linear' },
      gantt: { axisFormat: '%m/%d/%Y' },
      sequence: { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>




  

  

  

  

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">

<script>
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
      clientID: 'f3075553d7b0225df6ca',
      clientSecret: '68362ba87c4cc8e13103afcf729f5bd8ea176a78',
      repo: 'anemone95.github.io',
      owner: 'Anemone95',
      admin: ['Anemone95'],
      id: 'bd76488fe6fc1ecc0f2a40593c1b21fb',
        language: window.navigator.language || window.navigator.userLanguage,
      
      distractionFreeMode: 'true'
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
</script>

</body>
</html>
